<?php include "header.php"; ?>

      <div class="container">

<!------SEARCH-------->
	<div class="row">
		<div class="span7"></div>
		<div class="span3 offset2">
		<form class="form-search">
		  <div class="input-append">
		    <input type="text" class="span2 search-query">
		    <button type="submit" class="btn">Search</button>
		  </div>
		</form>
		</div>
      	</div>
<!------SEARCH EOF-------->

<!------BODY-------->

	<div class="row">
		<div class="span8">
		<!---- Content --->
			<div id="gallery" class="content">
				<div id="controls" class="controls"></div>
				<div class="slideshow-container">
					<div id="loading" class="loader"></div>
					<div id="slideshow" class="slideshow"></div>
				</div>
				<div id="caption" class="caption-container"></div>
			</div>
			<div id="thumbs" class="navigation">
				<ul class="thumbs noscript">
					<li>
						<a class="thumb" name="leaf" href="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015.jpg" title="Title #0">
							<img src="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_s.jpg" alt="Title #0" />
						</a>
						<div class="caption">
							<div class="download">
								<a href="http://farm4.static.flickr.com/3261/2538183196_8baf9a8015_b.jpg">Download Original</a>
							</div>
							<div class="image-title">Title #0</div>
							<div class="image-desc">Description</div>
						</div>
					</li>
				</ul>
			</div>
			<div style="clear: both;"></div>
		<!----end content -->
		</div>
		<div class="span4">
			<?php include"sidebar.php"?>
          	</div>	
	</div>

<!------BODY EOF-------->
      <hr>
    </div> <!-- /container -->

    <script>
        var messagesLength = 0;
        $(document).ready(
                function() {
                        $("#a").click(function() {
                                $("#form2").hide();
                                $("#form1").show();
                                $("#form3").hide();
                        });
                        $("#b").click(function() {
                                $("#form1").hide();
                                $("#form2").show();
                                $("#form3").hide();
                        });
                        
                        $('#search').keypress(function(event){
                                var keycode = (event.keyCode ? event.keyCode : event.which);
                                var id = document.getElementById("searching").value;
                                if(keycode == '13'){
                                        $.getJSON('services/manager/friendProfile/'+id, function(detail) {
                                                if (detail.emailAddress === null) {
                                                        alert("User tidak ditemukan.");
                                                } else {
                                                        alert(detail.emailAddress);
                                                }
                                        });
                                }
                        });
                        
                        $.getJSON('services/manager/messages', function(data) {
                                $.each(data.threads, function(key, val) {
                                        var liElement = document.createElement('li');
                                        var checkBox = document.createElement('input');
                                        var aElement = document.createElement('a');
                                        var participant = document.createElement('span')
                                        checkBox.type="checkbox";
                                        checkBox.value=val.id;
                                        aElement.href="#"+val.id;
                                        aElement.textContent=val.subject;
                                        aElement.setAttribute("style","padding: 10px !important");
                                        participant.textContent=val.participants.toString();
                                        liElement.appendChild(checkBox);
                                        liElement.appendChild(aElement);
                                        liElement.appendChild(participant);
                                        liElement.setAttribute("style","float:none !important; padding-bottom: 5px;");
                                        var ulElement = $("#form2 ul").append(liElement);
                                        $("#form2 ul li a").click(function(){
                                                var path = this.href;
                                                var id = path.substr(path.indexOf('#')+1, path.length);
                                                $.getJSON('services/manager/messages/'+id, function(detail) {
                                                                $("#messageDetail thead tr").children().remove();
                                                                $("#messageDetail thead tr").append("<th>"+detail.threads[0].subject+"</th>");
                                                                $.each(detail.threads[0].messages, function(detailkey, detailval) {
                                                                        $("#messageDetail tbody").children().remove();
                                                                        var detailRowSummary = document.createElement('tr');
                                                                        var detailValueSummaryLabel = document.createElement('td');
                                                                        var detailValueSummaryValue = document.createElement('td');
                                                                        detailValueSummaryLabel.textContent="Subject";
                                                                        detailValueSummaryValue.textContent=detail.threads[0].subject;
                                                                        detailRowSummary.appendChild(detailValueSummaryLabel);
                                                                        detailRowSummary.appendChild(detailValueSummaryValue);
                                                                        $("#messageDetail tbody").append(detailRowSummary);
                                                                        var detailRowContent = document.createElement('tr');
                                                                        var detailValueContent = document.createElement('td');
                                                                        detailValueContent.colSpan=2;
                                                                        detailValueContent.textContent=detailval.description;
                                                                        detailRowContent.appendChild(detailValueContent);
                                                                        $("#messageDetail tbody").append(detailRowContent);
                                                                });
                                                        $("#form3").show();
                                                        $("#form1").hide();
                                                        $("#form2").hide();
                                                });
                                        });
                                        //.apppend("<input type='checkbox' id='"+val.id+"'/>");
                                });
                                //.<span id='subject'><a href='javascript:showContent(\'"+val.id+"\')'>"+val.subject+"</a></span></li>
                        });
        });
       </script>
<?php include "footer.php"; ?>
